import React from 'react';
import { observer, inject } from 'mobx-react';
import { getEcCom,getAntd,getLabel } from '../../util/convert';
import * as Parse from '../../util/public/parseLayout';
import * as _ from '../../util/public/common';
import * as DetailUtil from '../../util/public/detailUtil';

@inject('globalStore', 'layoutStore')
@observer
export default class DPaging extends React.Component{
    constructor(){
        super();
    }
    render(){
        const { Pagination } = getAntd();
        const { symbol,globalStore,layoutStore } = this.props;
        const { JSComplete } = globalStore;
        const { workflowid } = globalStore.commonParam;
        const { dataJson,detailMap } = layoutStore;
        const detailLayout = dataJson.etables[symbol] || {};
        const headRow = parseInt(detailLayout.edtitleinrow || 0);
        const detailObj = detailMap.get(symbol);
        const groupid = detailObj.attr.groupid - 1;
        const { pagingInfo,rowInfoArr } = detailObj;
        const total = rowInfoArr.length;
        const { enabled,current,pagesize } = pagingInfo;
        if(!enabled)
            return null;
            
        return (
            <div className="wf-detail-paging">
                <Pagination ecId={`${this && this.props && this.props.ecId || ''}_Pagination@4tzss0`}
                    symbol={symbol}
                    showSizeChanger
                    showQuickJumper
                    total={total}
                    current={current}
                    showTotal={total => getLabel(385617, "共$s条").replace("$s", total)}
                    pageSize={pagesize}
                    pageSizeOptions={['10','20','30','50','100','150','200']}
                    onChange={(current) =>{
                        detailObj.controlPagingInfo({current});
                        DetailUtil.controlDetailPosition(groupid);
                        window.WfForm.triggerAction(window.WfForm.ACTION_SWITCHDETAILPAGING, [groupid], 200);
                    }}
                    onShowSizeChange={(current,pagesize) =>{
                        const params = { workflowid, groupid, pagesize};
                        detailObj.changePageSize(params);
                        DetailUtil.controlDetailPosition(groupid);
                        window.WfForm.triggerAction(window.WfForm.ACTION_SWITCHDETAILPAGING, [groupid], 200);
                    }}
                />
            </div>
        );
    }
}
